<script type="text/javascript" src="/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="/ueditor/ueditor.all.js"></script>
<!-- 编辑器公式插件 -->
<script type="text/javascript" charset="utf-8" src="/ueditor/kityformula-plugin/addKityFormulaDialog.js"></script>
<script type="text/javascript" charset="utf-8" src="/ueditor/kityformula-plugin/getKfContent.js"></script>
<script type="text/javascript" charset="utf-8" src="/ueditor/kityformula-plugin/defaultFilterFix.js"></script>
<div class="span10" id="datacontent">

    <ul class="breadcrumb">
        <li><a href="/test/question/index">测评题目</a> <span class="divider">/</span></li>
        <li><a href="/test/question/index">测评</a> <span class="divider">/</span></li>
        <li class="active">添加题目</li>
    </ul>
    <form action="/test/question/add" method="post" class="form-horizontal">
        <fieldset>
            <div class="control-group">
                <label for="area" class="control-label">试卷分类：</label>

                <div class="controls">
                    <select name="cateId" onchange="checkCate()" id="cate">
                        <option value="" >选择试卷</option>
                        <?php foreach ($option as $k => $v){ ?>
                            <option value="<?php echo $v['id']?>" <?php echo isset($data['cateId']) && $data['cateId'] == $v['id'] ? 'selected' : '' ?>><?php echo $v['name'] ?></option>
                        <?php } ?>
                    </select>
                </div>
            </div>
            <div class="control-group">
                <label for="area" class="control-label">科目分类：</label>
                <select name="subjectId" style="margin-left: 18px;" id="cateDetail">
                    <option value="">选择分类</option>
                    <?php foreach($subject as $v){?>
                        <option value="<?php echo $v['id']?>" <?php echo isset($data['subjectId'])&&$data['subjectId']==$v['id'] ? 'selected' : '' ?>><?php echo $v['name']?></option>
                    <?php }?>
                </select>
            </div>
            <div class="control-group">
                <label for="area" class="control-label">题型：</label>
                <select name="questionType" style="margin-left: 18px;" id="cateDetail">
                    <option value="">选择题型</option>
                    <option value="1" <?php echo isset($data['questionType']) && $data['questionType'] == 1 ? 'selected' : '' ?>>填空</option>
                    <option value="2" <?php echo isset($data['questionType']) && $data['questionType'] == 2 ? 'selected' : '' ?>>单选</option>
                    <option value="3" <?php echo isset($data['questionType']) && $data['questionType'] == 3 ? 'selected' : '' ?>>多选</option>
                </select>
            </div>
            <div class="control-group">
                <label for="area" class="control-label">题号：</label>

                <div class="controls">
                    <input type="text" name="name" value="<?php echo isset($data['name']) ? $data['name'] : '' ?>" />
                </div>
            </div>
            <div class="control-group">
                <label for="area" class="control-label">题干：</label>
                <div class="controls">
                    <textarea id="sss" name="question" style="height: 300px;"><?php echo isset($data['question']) ? $data['question'] : '' ?></textarea>
                </div>
            </div>

            <div class="control-group">
                <label for="area" class="control-label">原文/阅读：</label>

                <div class="controls">
                    <textarea  style="height:200px;width:300px" name="article"><?php echo isset($data['article']) ? $data['article'] : '' ?></textarea>
                </div>
            </div>
            <div class="control-group">
                <label for="area" class="control-label">听力文件：</label>

                <div class="controls">
                    <input type="text" value="<?php echo isset($data['listenFile']) ? $data['listenFile'] : '' ?>" class="title_image" name="listenFile">
                    <a href="#" class="btn btn-info" onclick="upFiles()">上传文件</a>
                </div>
            </div>

            <div class="control-group">
                <label for="area" class="control-label">选项：</label>
                <div class="controls">
                    <textarea type="text" name="option" style="height:200px;"><?php echo isset($data['option']) ? $data['option'] : '' ?></textarea>
                </div>
            </div>

            <div class="control-group">
                <div class="controls">
                    <input type="hidden" name="id" value="<?php echo isset($_GET['id'])?$_GET['id']:''?>"/>
                    <button class="btn btn-primary" type="submit">提交</button>
                </div>
            </div>
        </fieldset>
    </form>
</div>

<script>
    //实例化编辑器
    //题干
    var o_ueditorupload = UE.getEditor('sss',
        {
            autoHeightEnabled: false
        });

    o_ueditorupload.ready(function () {

        // o_ueditorupload.hide();//隐藏编辑器

        //监听图片上传
        o_ueditorupload.addListener('beforeInsertImage', function (t, arg) {
            $('.image').val(arg[0].src);

        });

        /* 文件上传监听
         * 需要在ueditor.all.min.js文件中找到
         * d.execCommand("insertHtml",l)
         * 之后插入d.fireEvent('afterUpfile',b)
         */
        o_ueditorupload.addListener('afterUpfile', function (t, arg) {

        });
    });
    //题目
//    var o_ueditorupload = UE.getEditor('article',
//        {
//            autoHeightEnabled: false
//        });

    o_ueditorupload.ready(function () {

        // o_ueditorupload.hide();//隐藏编辑器

        //监听图片上传
        o_ueditorupload.addListener('beforeInsertImage', function (t, arg) {
            $('.image').val(arg[0].src);

        });

        /* 文件上传监听
         * 需要在ueditor.all.min.js文件中找到
         * d.execCommand("insertHtml",l)
         * 之后插入d.fireEvent('afterUpfile',b)
         */
        o_ueditorupload.addListener('afterUpfile', function (t, arg) {

        });
    });

    // 标题图片
    var o_ueditorupload2 = UE.getEditor('j_ueditorupload2',
        {
            autoHeightEnabled: false
        });

    o_ueditorupload2.ready(function () {

        o_ueditorupload2.hide();//隐藏编辑器

        //监听图片上传
        o_ueditorupload2.addListener('afterUpfile', function (t, arg) {
            $('.title_image').val('https://www.thinkuprep.com'+arg[0].url);

        });

        /* 文件上传监听
         * 需要在ueditor.all.min.js文件中找到
         * d.execCommand("insertHtml",l)
         * 之后插入d.fireEvent('afterUpfile',b)
         */
        o_ueditorupload2.addListener('afterUpfile', function (t, arg) {

        });
    });
    //弹出图片上传的对话框
    function upFiles() {
        var myFiles = o_ueditorupload2.getDialog("attachment");
        myFiles.open();
    }
</script>
<script type="text/plain" id="sss"></script>
<script type="text/plain" id="j_ueditorupload2"></script>
<script type="text/plain" id="j_ueditorupload3"></script>
<script>
    function checkCate() {
        var options = $("#cate option:selected");
        var cate = options.val();
        $.post('/test/api/test-cate', {
            cate: cate,
        }, function (res) {
            if (res.code == 1) {
                $('#cateDetail').empty();
                var option = '<select name="subject" id="cateDetail" style="margin-left: 18px;"><option value="">选择分类</option>';
                for (var i = 0; i < res.allCate.length; i++) {
                    option += '<option value="' + res.allCate[i]['id'] + '">' + res.allCate[i]['name'] + '</option>'
                }
                option += '</select>';
                $('#cateDetail').html(option);
            } else {
                alert(res.message)
            }
        }, 'json')
    }

</script>